// 生成用户的临时身份的唯一标识  UUID
import { v4 as uuidv4 } from 'uuid';

export function userTempId() {
  //先从本地存储获取 userTempId
  let result = localStorage.getItem('userTempId');

  if (result) {
    //若拿到userTempId ，直接返回
    return result;
  } else {
    //重新生成
    let newUserTempId = uuidv4();
    //本地存储  数据
    localStorage.setItem('userTempId', newUserTempId);
    //返回新生成的 newUserTempId
    return newUserTempId;
  }
}
//本地存储token
export function saveToken(token) {
  localStorage.setItem('token', token);
}
//读取token
export function readToken() {
  return localStorage.getItem('token');
}
//删除token
export function deleteToken() {
  return localStorage.removeItem('token');
}
